package com.xw.comm.controller;

import com.xw.comm.entity.BaseResponse;
import com.xw.comm.entity.CobraResultCodeConstant;
import com.xw.comm.entity.ResultCode;
import com.xw.comm.service.PythonRunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：xiongwei
 * @date ：Created in 2021/2/28 23:15
 */
@Slf4j
@RestController
@RequestMapping("/test")
@Api(value = "TestController | 测试接口")
public class TestController {

    @Autowired
    private PythonRunService pythonRunService;

    @GetMapping(value = "/testPage")
    @ApiOperation(value = "测试页面 ", notes = "测试接口")
    public BaseResponse testPage() {
        ResultCode resultCode = new ResultCode(CobraResultCodeConstant.SUCCESS.getCode(),"testPage");
        log.info("testPage = {}", "测试页面");
        return new BaseResponse(resultCode);
    }

    @GetMapping(value = "/receiveData")
    @ApiOperation(value = "接收数据 ", notes = "接收的是识别结果字符串")
    @ApiImplicitParam(paramType = "query", name = "data", value = "数据", required = false, dataType = "String")
    public BaseResponse receiveData(@RequestParam(value = "data", required = true, defaultValue = "") String receiveData) {
        ResultCode resultCode = new ResultCode(CobraResultCodeConstant.SUCCESS.getCode(),receiveData);
        log.debug("receiveData = {}", receiveData);
        return new BaseResponse(resultCode);
    }

    @GetMapping(value = "/testAsync")
    @ApiOperation(value = "测试异步 ", notes = "接收的是识别结果字符串")
    @ApiImplicitParam(paramType = "query", name = "asyncName", value = "异步名称", required = false, dataType = "String")
    public BaseResponse testAsync(@RequestParam(value = "asyncName", required = true, defaultValue = "") String asyncName) {
        ResultCode resultCode = new ResultCode(CobraResultCodeConstant.SUCCESS.getCode(),asyncName);
        pythonRunService.runAsyncPythonFile(asyncName);
        log.info("testAsync = {}", asyncName);
        return new BaseResponse(resultCode);
    }

}


